//
//  File.swift
//
//
//  Created by didi on 2022/9/13.
//

import Vapor

public final class DeleteForm: AbstractForm {
    public init() {
        super.init()
        action.method = .post
        submit = "Delete"
    }
}

public protocol DeleteController: ModelController {
    func deleteAccess(_ req: Request) async throws -> Bool
    func beforeDelete(_ req: Request, _ model: DatabaseModel) async throws
    func afterDelete(_ req: Request, _ model: DatabaseModel) async throws
}

public extension DeleteController {
    func deleteAccess(_ req: Request) async throws -> Bool {
        try await req.checkAccess(for: ApiModel.permission(for: .delete))
    }

    func beforeDelete(_ req: Request, _ model: DatabaseModel) async throws {
    }

    func afterDelete(_ req: Request, _ model: DatabaseModel) async throws {
    }
}
